<?php
define("DEPLOYED",false);
require "global.php";
require "taobao.php";

$pro_db = new PormotionDB();

$sort_array = explode(",", "女装,男装,女鞋,男鞋,运动户外,女包,化妆品,配饰,家居,手机数码,母婴");
$excel = new ExcelReport();
$data = $excel->readExcel("./taobao_1111.xls");
$i = 0;
foreach ( $data->sheets as $sheet ) {
	$t = 0;
	if($i>=10){
		foreach ( $sheet ['cells'] as $ds ) {
			if ($t ++ < 357)
				continue;
			$row = array ();
			$row['brand_name'] = str_replace("'", "’", $ds[1]);
			$row['goods_title'] = str_replace("'", "’", $ds[2]);
			$row['price'] = $ds [3];
			$row['off_price'] = $ds [4];
			$row['sort'] = iconv ( 'utf-8', 'gbk', $sort_array[$i] );
			$row['holiday'] = '20121111';
			
			$id = $pro_db->checkPromotionExist($row['brand_name'], $row['goods_title'],$ds[5]);
			
			if($id!=0){
				$pro_db->updatePromotionSort($id, $row ['sort']);
			}else{
				
				if (strlen ( $ds [5] ) > 0) {
					$row ['baidu_url'] = $ds [5];
					$row ['goods_url'] = decodeBaiduShortUrl ( $ds [5] );
				} else {
					$row ['baidu_url'] = "";
				}
				if (strlen ( $ds [6] ) > 0) {
					$row ['weibo_url'] = $ds [6];
					if (! isset ( $row ['goods_url'] ))
						$row ['goods_url'] = decodeSinaShortUrl ( $ds [6] );
				} else {
					$row ['weibo_url'] = "";
				}
				
				$pro_db->insertPromotion ( $row );
			}		
	
			echo (implode ( ",", $row ) . PHP_EOL);
		}
	}
	$i ++;
}
?>